/********************************************/
  // Creation History
  // --------------------------------------------------------------
  //	Company:			HTHK
  //	NAME:				StaffOptions.java
  //    Title   :			get the Staff_no into a list box
  //	FUNCTION:
  //	BY:					Beyes Xia
  //	DATE:				16/12/2003
  // --------------------------------------------------------------
/*********************************************/
/*--------------------------------------------------------------
  Amend record
  Date          Version         Author          Description
  01/07/2004    1.0             Beyes           For log 1304.
---------------------------------------------------------------*/
package tss.options;

import java.sql.*;
import java.util.*;

import org.apache.log4j.Logger;

import com.ffpc.sql.*;
import com.util.JdbcUtil;

public class StaffOptions
{	
	private Logger logger = Logger.getLogger(StaffOptions.class);
	private Vector optionValue = new Vector();
	private String optionHtml = "";
	
	private boolean allFlag = true;
		
  	public void createOptions()
  	{
  		ConnectionFactory connectionFactory = null;
		Connection con = null;
		Statement stmt = null;
		ResultSet rs = null;
		
		String sql = "select staff_no,alias,surname "+ 
					"from tss.tss_c_employee ";
//---------------- Add by Beyes Xia for log 1304 7/1/2004 3:34 PM ----------------
		if(!this.allFlag)
			sql += "where (last_date Is Null Or trunc(last_date) > trunc(Sysdate)) ";
//---------------- End add by Beyes Xia -----------------------------					
		sql += "order by alias";
//logger.debug("sql="+sql);
		try
		{
	  		connectionFactory = new ConnectionFactory("fasp_tss");
	  		con = connectionFactory.getConnection();
	  		stmt = con.createStatement();
	  		rs = stmt.executeQuery(sql);
	  		while(rs.next())
	  		{
	  			
	  			String[] option_value = new String[2];
	  			option_value[0] = rs.getString(1);
	  			option_value[1] = (rs.getString(2)== null?"":rs.getString(2))+
	  							" "+rs.getString(3)+" ["+rs.getString(1)+"]";
//logger.debug(option_value[0]);
//logger.debug(option_value[1]);
	  			optionValue.addElement(option_value);
//logger.debug("option_value.size()="+optionValue.size());
	  		}
	  		stmt.close();
  		}
  		catch (Exception e)
  		{
  			logger.error("Exception:"+e.getMessage());
  		}
        finally
        {
        	JdbcUtil.release(stmt, rs);
            try
            {
                connectionFactory.finalize();       
            }
            catch (Exception ex) 
            {
                logger.error("Exception:"+ex.getMessage());
            }
        }  		
  	}

//---------------- Add by Beyes Xia for log 1304 7/1/2004 4:19 PM ----------------  	
  	public StaffOptions(String activation)
  	{
  		if(activation.equals("activation"))
  		{
  			this.allFlag = false;
  		}
  		createOptions();
  	}
  	public StaffOptions()
  	{
  		createOptions();
  	}
//--------------- End add by Beyes Xia ------------------------------
 	
  	public Vector getVectorValue()
  	{
  		return optionValue;
  	}
  	
	public String getOptions()
	{
		StringBuffer sb = new StringBuffer();
		sb.append("<option value=\"\"></option>\n");
		for(int i=0;i<optionValue.size();i++)
		{
			String[] option_value = new String[2];
			option_value = (String[])optionValue.get(i);
			sb.append("<option value=\""+option_value[0]+"\">"+option_value[1]+"</option>\n");
		}
		optionHtml = sb.toString();
//logger.debug("optionHtml:"+optionHtml);
		return optionHtml;
	}
	public String getOptions(String defaultOptions)
	{
		StringBuffer sb = new StringBuffer();
		sb.append("<option value=\"\"></option>\n");
		for(int i=0;i<optionValue.size();i++)
		{
			String[] option_value = new String[2];
			option_value = (String[])optionValue.get(i);
			boolean selected = false;				
			if(option_value[0].equals(defaultOptions))
					selected = true;
			if(!selected)
				sb.append("<option value=\""+option_value[0]+"\">"+option_value[1]+"</option>\n");
			else
				sb.append("<option value=\""+option_value[0]+"\" selected>"+option_value[1]+"</option>\n");
		}
		optionHtml = sb.toString();
//logger.debug("optionHtml:"+optionHtml);
		return optionHtml;
	}
	
	public String getOptions(String defaultOptions,boolean flag)
	{
		if(flag)
		{
			optionHtml = this.getOptions(defaultOptions);
		}
		else
		{
			optionHtml = this.getOptions(defaultOptions);
		}
		return optionHtml;
	}	
}



